<?php
/**
 * This controller is uses to test
 *
 * @author	huytbt
 * @date	2012-06-05
 * @version	1.0
 */
class TestController extends HController
{
	public function actionFormatDepartments()
	{
		set_time_limit(0);
		Yii::import('application.modules.textbooks.models.TextbookDepartment');
		$departments = TextbookDepartment::model()->findAll();
		foreach ($departments as $department) {
			$department->name = trim($department->name);
			$department->save();
		}
		echo 'OK';
	}
	
	public function actionImportDepartments()
	{
		exit;
		set_time_limit(0);
		Yii::import('application.modules.textbooks.models.TextbookDepartment');
		
		$handle = @fopen(dirname(__FILE__) . '/PCC.txt', "r");
		if ($handle) {
			while (($buffer = fgets($handle, 4096)) !== false) {
				echo $buffer . ': ';
				$department = new TextbookDepartment;
				$department->name = $buffer;
				$department->university_id = 3;
				$department->books = 0;
				$department->status = 1;
				// echo $department->validate() . '<br/>';
				if ($department->save()) echo '<b>OK</b><br/>';
			}
			if (!feof($handle)) {
				echo "Error: unexpected fgets() fail\n";
			}
			fclose($handle);
		}
	}
}
